package com.example.dao;

import jakarta.persistence.*;
import java.sql.Timestamp;
import java.io.Serializable;

@Entity
@IdClass(SlowSqlInfo.SlowSqlInfoId.class) // 指定复合主键类
public class SlowSqlInfo {

    // 复合主键类必须实现 Serializable 接口
    public static class SlowSqlInfoId implements Serializable {
        private String host;
        private String fingerprint;
        private String rawFilePath;

        // 无参构造器
        public SlowSqlInfoId() {}

        // 带参构造器
        public SlowSqlInfoId(String host, String fingerprint, String rawFilePath) {
            this.host = host;
            this.fingerprint = fingerprint;
            this.rawFilePath = rawFilePath;
        }

        // getter 和 setter 方法
        public String getHost() {
            return host;
        }

        public void setHost(String host) {
            this.host = host;
        }

        public String getFingerprint() {
            return fingerprint;
        }

        public void setFingerprint(String fingerprint) {
            this.fingerprint = fingerprint;
        }

        public String getRawFilePath() {
            return rawFilePath;
        }

        public void setRawFilePath(String rawFilePath) {
            this.rawFilePath = rawFilePath;
        }

        // 重写 equals 和 hashCode 方法
        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            SlowSqlInfoId that = (SlowSqlInfoId) o;

            if (!host.equals(that.host)) return false;
            if (!fingerprint.equals(that.fingerprint)) return false;
            return rawFilePath.equals(that.rawFilePath);
        }

        @Override
        public int hashCode() {
            int result = host.hashCode();
            result = 31 * result + fingerprint.hashCode();
            result = 31 * result + rawFilePath.hashCode();
            return result;
        }
    }

    // 使用 @Id 注解标记复合主键字段
    @Id
    private String host;

    @Id
    @Column(columnDefinition = "text")
    private String fingerprint;

    @Id
    @Column(columnDefinition = "text")
    private String rawFilePath;

    private String checksum;
    @Column(columnDefinition = "text")
    private String distillate;
    private String queryCount;
    private String tsMin;
    private String tsMax;
    private String db;
    private String port;
    private String clientHost;
    private String username;
    private String queryTimeSum;
    private String queryTimeAvg;
    private String queryTimePctInGlobal;
    private String rawFileSize;
    private String jsonFilePath;
    private Timestamp updateTime;

    public String getChecksum() {
        return checksum;
    }

    public void setChecksum(String checksum) {
        this.checksum = checksum;
    }

    public String getDistillate() {
        return distillate;
    }

    public void setDistillate(String distillate) {
        this.distillate = distillate;
    }

    public String getFingerprint() {
        return fingerprint;
    }

    public void setFingerprint(String fingerprint) {
        this.fingerprint = fingerprint;
    }

    public String getQueryCount() {
        return queryCount;
    }

    public void setQueryCount(String queryCount) {
        this.queryCount = queryCount;
    }

    public String getTsMin() {
        return tsMin;
    }

    public void setTsMin(String tsMin) {
        this.tsMin = tsMin;
    }

    public String getTsMax() {
        return tsMax;
    }

    public void setTsMax(String tsMax) {
        this.tsMax = tsMax;
    }

    public String getDb() {
        return db;
    }

    public void setDb(String db) {
        this.db = db;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getPort() {
        return port;
    }

    public void setPort(String port) {
        this.port = port;
    }

    public String getClientHost() {
        return clientHost;
    }

    public void setClientHost(String clientHost) {
        this.clientHost = clientHost;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getQueryTimeSum() {
        return queryTimeSum;
    }

    public void setQueryTimeSum(String queryTimeSum) {
        this.queryTimeSum = queryTimeSum;
    }

    public String getQueryTimeAvg() {
        return queryTimeAvg;
    }

    public void setQueryTimeAvg(String queryTimeAvg) {
        this.queryTimeAvg = queryTimeAvg;
    }

    public String getQueryTimePctInGlobal() {
        return queryTimePctInGlobal;
    }

    public void setQueryTimePctInGlobal(String queryTimePctInGlobal) {
        this.queryTimePctInGlobal = queryTimePctInGlobal;
    }

    public String getRawFilePath() {
        return rawFilePath;
    }

    public void setRawFilePath(String rawFilePath) {
        this.rawFilePath = rawFilePath;
    }

    public String getRawFileSize() {
        return rawFileSize;
    }

    public void setRawFileSize(String rawFileSize) {
        this.rawFileSize = rawFileSize;
    }

    public String getJsonFilePath() {
        return jsonFilePath;
    }

    public void setJsonFilePath(String jsonFilePath) {
        this.jsonFilePath = jsonFilePath;
    }

    public Timestamp getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Timestamp updateTime) {
        this.updateTime = updateTime;
    }
}
